<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form v-if="tabsKeys == 1" size="small" :model="pageData" layout="inline">
            <a-form-item label="单号">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" v-model="pageData.g"/>
            </a-form-item>
            <CorporateSectorCascader :configCascader="configCascader2" @changeCascader="changeCascader2"/>
            <a-form-item label="仓库">
              <a-select popup-container="html" class="bacClass" :style="{ width: '10rem' }" v-model="pageData.b"
                        allow-clear>
                <a-option v-for="item in fhWhList" :value="item.id">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
          </a-form>
          <a-form v-else-if="tabsKeys == 2" size="small" :model="pageData" layout="inline">
            <a-form-item label="采购单号">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" v-model="pageData.h"/>
            </a-form-item>
            <CorporateSectorCascader :configCascader="configCascader" @changeCascader="changeCascader"/>
            <a-form-item label="物料编号">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" v-model="pageData.d"/>
            </a-form-item>
            <a-form-item label="物料名称">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" v-model="pageData.e"/>
            </a-form-item>
          </a-form>
          <a-form v-else-if="tabsKeys == 3" size="small" :model="pageData" layout="inline">
            <a-form-item label="单号">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" v-model="pageData.f"/>
            </a-form-item>
          </a-form>
        </div>
        <div style="text-align: end;">
          <Toolbar :items="toolbarList" @select="selectHandler" @rejected="rejecteds" @reders="redersOut" @del="delSles"
                   @audit="audits" @complete="completes" @print="printRef">
          </Toolbar>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18"/>
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18"/>
        </a-divider>
      </div>
    </template>
    <template #pageTabel>
      <a-tabs   :lazy-load="true" :justify="true" :default-active-key="tabsKeys" @change="tabsChanges">
        <a-tab-pane title="已处理" :key="1">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                           rowSelection="multiple" @grid-ready="gridReady"
                           style="height: calc(100% - 45px)" :defaultColDef="defaultColDef" class='ag-theme-alpine'
                           :rowData="tableDataList"
                           :columnDefs="tc" :localeText="localeText1"></AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="fySelet2.total" show-total show-jumper
                           show-page-size
                           @change="PageSize2" @page-size-change="change2" style="justify-content: center"
                           :page-size="fySelet2.size" :current="fySelet2.page"/>
        </a-tab-pane>
        <a-tab-pane title="采购单待处理" :key="2">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                           rowSelection="multiple" @grid-ready="gridReady2"
                           style="height: calc(100% - 45px)" :defaultColDef="defaultColDef2" class='ag-theme-alpine'
                           :rowData="tableDataList2"
                           :columnDefs="tc2" :localeText="localeText1"></AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="fySelet.total" show-total show-jumper show-page-size
                           @change="PageSize" @page-size-change="change" style="justify-content: center"
                           :page-size="fySelet.size"
                           :current="fySelet.page"/>
        </a-tab-pane>
        <a-tab-pane title="打印列表" :key="3">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                           rowSelection="multiple" @grid-ready="gridReady3"
                           style="height: calc(100% - 45px)" :defaultColDef="defaultColDef3" class='ag-theme-alpine'
                           :rowData="tableDataList3"
                           :columnDefs="tc3" :localeText="localeText1"></AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="fySelet3.total" show-total show-jumper
                           show-page-size
                           @change="PageSize3" @page-size-change="change3" style="justify-content: center"
                           :page-size="fySelet3.size" :current="fySelet3.page"/>
        </a-tab-pane>
      </a-tabs>
    </template>
    <a-modal v-model:visible="cgOut.visible" :on-before-ok="cgHandleOk" @cancel="cadelvs" fullscreen
             :mask-closable="false">
      <template #title>
        {{ cgOut.title }}
      </template>
      <div v-if="tabsKeys == 2" :style="{ marginBottom: '10px' }">
        <span>入库仓库: </span>
        <a-select popup-container="html" :style="{ width: '200px' }" @change="warehouseChange" class="bacClass"
                  v-model="warehouseNameAanId" allow-clear allow-search>
          <a-option v-for="item in cgRoutList" :value="item.id + '-' + item.warehouseName">{{
              item.warehouseName
            }}
          </a-option>
        </a-select>
      </div>
      <a-table v-if="tabsKeys == 2" :columns="cgColumns" :data="cgData" :pagination="false" :bordered="{ cell: true }">
        <template #totalNum="{ record }">
          <a-input-number class="bacClass" v-model="record.totalNum"></a-input-number>
        </template>
        <template #location="{ record }">
          <a-select popup-container="html" :style="{ width: '150px' }" :loading="loading" @search="handleSearch"
                    class="bacClass"
                    v-model="record.location" :filter-option="false" allow-search allow-clear @focus="focusSel">
            <a-option v-for="item in pageData.locationList" :value="item['storageName']">{{
                item['storageName']
              }}
            </a-option>
          </a-select>
        </template>
        <!-- <template #warehouseName="{ record }">
                <a-select popup-container="html"  @change="warehouseChange($event, record)" class="bacClass" v-model="record.warehouseName"
                    allow-clear allow-search>
                    <a-option v-for="item in cgRoutList" :value="item.id + '-' + item.warehouseName">{{
                        item.warehouseName
                    }}</a-option>
                </a-select>
            </template> -->
        <template #grade="{ record }">
          <a-input class="bacClass" v-model="record.grade" allow-clear></a-input>
          <!-- <a-select popup-container="html"  @click="gradeChange" class="bacClass" v-model="record.grade" allow-clear allow-search>
              <a-option v-for="item in gradrList">{{
                  item.detailName
              }}</a-option>
          </a-select> -->
        </template>
      </a-table>
      <a-table v-else-if="tabsKeys == 3" :columns="cgColumns2" :data="cgData2" :pagination="false"
               :bordered="{ cell: true }">
        <template #grade="{ record }">
          <a-input class="bacClass" v-model="record.grade" allow-clear></a-input>
          <!-- <a-select popup-container="html"  @click="gradeChange" class="bacClass" v-model="record.grade" allow-clear allow-search>
              <a-option v-for="item in gradrList">{{
                  item.detailName
              }}</a-option>
          </a-select> -->
        </template>
      </a-table>
    </a-modal>
    <a-modal ok-text="打印" :width="900" v-model:visible="visibleYl2" :on-before-ok="handleOks2"
             @cancel="handleCancels2">
      <template #title>胶管入库单</template>
      <div id="wjDyings4">
        <div class="No1">
          <div class="No1-1">肇庆市粤隆纺织有限公司</div>
          <div class="No1-2">胶管入库单</div>
          <div class="No1-3">
            <div>入库单号:&nbsp;&nbsp;{{ printDatas?.orderNo }}</div>
            <div>供货单位:&nbsp;&nbsp;{{ printDatas?.supplierName }}</div>
          </div>
          <div class="No1-4">
            <div>开单日期:&nbsp;&nbsp;{{ printDatas?.createTime }}</div>
            <div>入库类型:&nbsp;&nbsp;{{ printDatas?.inStockType }}</div>
            <div>收料人:</div>
          </div>
          <div class="No1-5">
            <div>备注:</div>
          </div>
        </div>
        <table class="isTable">
          <tr>
            <th>产品编号</th>
            <th>产品名称</th>
            <th>批次</th>
            <th>规格</th>
            <th>单位</th>
            <th>数量</th>
            <th>单价</th>
            <th>金额</th>
            <th>备注</th>
          </tr>
          <tr v-for="item in printDataLists">
            <td>{{ item.materialCode }}</td>
            <td>{{ item.materialName }}</td>
            <td>{{ item.grade }}</td>
            <td>{{ item.specification }}</td>
            <td>{{ item.unit }}</td>
            <td>{{ item.totalNum }}</td>
            <td>{{ item.price }}</td>
            <td></td>
            <td></td>
          </tr>
        </table>
      </div>
    </a-modal>
  </pageTabelLayout>
</template>
<script setup lang="ts">
import {ref, reactive} from "vue"
import {post, get} from "@/api/http"
import {localeText} from '@/api/aggridZw'

import Toolbar from "@/components/Toolbar.vue"
import {Message, Modal} from "@arco-design/web-vue"
import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
import WHService from '@/service/wh'
import printJS from 'print-js'
import {pagingList} from '@/api/paging'

const pagingList1: any = ref(pagingList)
const toolbarList: any = ref(['查询', '审核', '删除'])

const fySelet: any = reactive({
  total: 10,
  size: 10,
  page: 1
})

const PageSize = (val: any) => {
  fySelet.page = val
  cxCgsList()
}

const change = (val: any) => {
  fySelet.size = val
  cxCgsList()
}

const fySelet2: any = reactive({
  total: 10,
  size: 10,
  page: 1
})

const PageSize2 = (val: any) => {
  fySelet2.page = val
  cxYcList()
}

const change2 = (val: any) => {
  fySelet2.size = val
  cxYcList()
}

const fySelet3: any = reactive({
  total: 10,
  size: 10,
  page: 1
})

const PageSize3 = (val: any) => {
  fySelet2.page = val
  cxDbsList()
}

const change3 = (val: any) => {
  fySelet2.size = val
  cxDbsList()
}

const headerShow = ref(true)

const pageData: any = reactive({
  a: '',
  b: '',
  c: '',
  d: '',
  e: '',
  f: '',
  g: '',
  h: '',
  locationList: []
})

const tableDataList = ref([])

const tableDataList2: any = ref([])

const tableDataList3 = ref([])


const gridOption = ref()
const gridReady = (params: any) => {
  gridOption.value = params.api
}

const gridOption2 = ref()
const gridReady2 = (params: any) => {
  gridOption2.value = params.api
}

const gridOption3 = ref()
const gridReady3 = (params: any) => {
  gridOption3.value = params.api
}

const defaultColDef = {
  sortable: true,
  resizable: true,
  filter: true,
}

const defaultColDef2 = {
  sortable: true,
  resizable: true,
  filter: true,
}

const defaultColDef3 = {
  sortable: true,
  resizable: true,
  filter: true,
  flex: 1,
}

const localeText1: any = ref(localeText)

const tc = [
  {
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
  },
  {
    headerName: '单号',
    field: 'orderNo',
    // pinned: o['fixed'],
    width: 150,
    filter: 'agSetColumnFilter',
  },
  {
    headerName: '入库类型',
    field: 'inStockType',
    width: 150
  },
  {
    headerName: '公司',
    field: 'companyName',
    width: 150
  },
  {
    headerName: '仓库类型',
    field: 'warehouseTypeName',
    width: 150
  },
  {
    headerName: '仓库名称',
    field: 'warehouseName',
    width: 150
  },
  {
    headerName: '采购单号',
    field: 'purchaseOrderNo',
    width: 150
  },
  {
    headerName: '供应商名称',
    field: 'supplierName',
    width: 150
  },
  {
    headerName: '客户名称',
    field: 'customerName',
    width: 150
  },
  {
    headerName: '物料大类',
    field: 'majorCategory',
    width: 150
  },
  {
    headerName: '物料小类',
    field: 'subCategory',
    width: 150
  },
  {
    headerName: '物料编号',
    field: 'materialCode',
    width: 150
  },
  {
    headerName: '物料名称',
    field: 'materialName',
    width: 150
  },
  {
    headerName: '规格',
    field: 'specification',
    width: 150
  },
  {
    headerName: '总数',
    field: 'totalNum',
    width: 150
  },
  {
    headerName: '单位',
    field: 'unit',
    width: 150
  },
  // {
  //     headerName: '批次',
  //     field: 'grade',
  //     width: 150
  // },
  {
    headerName: '储位',
    field: 'location',
    width: 150
  },
  {
    headerName: '创建人',
    field: 'createName',
    width: 150
  },
  {
    headerName: '创建时间',
    field: 'createTime',
    width: 150
  },
  {
    headerName: '修改人',
    field: 'updateName',
    width: 150
  },
  {
    headerName: '修改时间',
    field: 'updateTime',
    width: 150
  },
  {
    headerName: '状态',
    field: 'infoState',
    pinned: 'right',
    width: 150,
    cellRenderer: {
      template: `
        <a-button v-if="states == 2" status="success">已入库</a-button>
        <a-button v-else="states == 0" type="dashed" status="success">待审核</a-button>
      `,
      setup(props: any) {
        return {
          states: props.params.data.infoState
        }
      }
    }
  }
]

const tc2 = [
  {
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
  },
  {
    headerName: '采购单号',
    field: 'purchaseOrderNo',
    // pinned: o['fixed'],
    width: 150
  },
  {
    headerName: '采购公司',
    field: 'companyName',
    // pinned: o['fixed'],
    width: 150
  },
  {
    headerName: '供应商',
    field: 'supplierName',
    width: 150
  },
  {
    headerName: '采购员',
    field: 'buyer',
    width: 150
  },
  {
    headerName: '客户名称',
    field: 'clientName',
    width: 150
  },
  {
    headerName: '物料大类',
    field: 'majorCategory',
    width: 150
  },
  {
    headerName: '物料小类',
    field: 'subCategory',
    width: 150
  },
  {
    headerName: '物料名称',
    field: 'materialName',
    width: 150
  },
  {
    headerName: '物料编号',
    field: 'materialCode',
    width: 150
  },
  {
    headerName: '规格',
    field: 'specification',
    width: 150
  },
  {
    headerName: '单位',
    field: 'unit',
    width: 150
  },
  {
    headerName: '批次',
    field: 'grade',
    width: 150
  },
  {
    headerName: '采购数量',
    field: 'totalNum',
    width: 150
  },
  {
    headerName: '采购单位',
    field: 'purchaseUnit',
    width: 150
  },
  // {
  //     headerName: '换算数量',
  //     field: 'totalNum',
  //     width: 150
  // },
  // {
  //     headerName: '换算单位',
  //     field: 'unit',
  //     width: 150
  // },
  {
    headerName: '已入库数量',
    field: 'inStockNum',
    width: 150
  },
  {
    headerName: '未入库数量',
    field: 'notInStockNum',
    width: 150
  },
  {
    headerName: '单价',
    field: 'price',
    width: 150
  },
  {
    headerName: '价格',
    field: 'noTaxMoney',
    width: 150
  },
]

const tc3 = [
  {
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
  },
  {
    headerName: '单号',
    field: 'orderNo',
    // pinned: o['fixed'],
    width: 150,
    filter: 'agSetColumnFilter',
  },
  {
    headerName: '入库类型',
    field: 'inStockType',
    width: 150
  },
  {
    headerName: '公司',
    field: 'companyName',
    width: 150
  },
  {
    headerName: '仓库类型',
    field: 'warehouseTypeName',
    width: 150
  },
  {
    headerName: '仓库名称',
    field: 'warehouseName',
    width: 150
  },
  {
    headerName: '采购单号',
    field: 'purchaseOrderNo',
    width: 150
  },
  {
    headerName: '创建人',
    field: 'createName',
    width: 150
  },
  {
    headerName: '创建时间',
    field: 'createTime',
    width: 150
  },
  {
    headerName: '操作',
    field: 'aouts',
    pinned: 'right',
    width: 150,
    cellRenderer: {
      template: `
        <a-button @click="a" type="primary" size="small">打印</a-button>
      `,
      setup(props: any) {
        const a = () => {
          printDatas.value = props.params.data
          // visibleYl2.value = true
          post({
            url: 'dwWms/dwRubberInStock/getList',
            data: {orderNo: [props.params.data.orderNo]},
            responseType: 'blob'
          }).then((res) => {
            let reader = new FileReader();
            reader.readAsDataURL(res);
            reader.onload = function () {
              let pdfBase64 = reader.result.replace('data:application/pdf;base64,', '');
              printJS({printable: pdfBase64, type: 'pdf', base64: true})
            };
          });
        }
        return {
          a
        }
      }
    }
  }
]

const printDatas: any = ref()
const printDataLists: any = ref()

const selectHandler = () => {
  if (tabsKeys.value == 1) {
    cxYcList()
  } else if (tabsKeys.value == 2) {
    cxCgsList()
  } else if (tabsKeys.value == 3) {
    cxDbsList()
  }
}

const tabsKeys = ref(1)

const tabsChanges = (e: any) => {
  tabsKeys.value = e
  if (e == 1) {
    toolbarList.value = ['查询', '审核', '删除']
  } else if (e == 2) {
    toolbarList.value = ['查询', '入库', '完成']
  } else if (e == 3) {
    toolbarList.value = ['查询', '入库', '驳回', '打印']
  }
}

const cgDcuList = reactive({
  pwDds: '',
  pwDds2: '',
})

const cxCgsList = async () => {
  // isWlNameds,
  // isWlCodeds,
  post({
    url: 'dwPurchase/PurchaseOrder/getPurchaseCode',
    data: {
      // purchaseCode: isCgds.value,
      companyId: pageData.c == '' ? null : pageData.c,
      page: fySelet.page,
      size: fySelet.size,
      purchaseOrderNo: pageData.h,
      materialCode: pageData.d,
      materialName: pageData.e,
      purchaseType: "胶管采购"
    }
  }).then((res: any) => {
    gridOption2.value.setRowData(res.data.data)
    tableDataList2.value = res.data.data
    fySelet.total = res.data.total
  })
}

const cxDbsList = () => {
  post({
    url: 'dwWms/dwRubberInStock/getPrintList',
    data: {
      page: fySelet3.page,
      size: fySelet3.size,
      orderNo: pageData.f,
      // inWarehouseTypeName: '五金仓',
      // orderNo: pageData.f,
      // infoType: 2,
      // infoState: 2
    }
  }).then((res: any) => {
    gridOption3.value.setRowData(res.data.data)
    tableDataList3.value = res.data.data
    fySelet3.total = res.data.total
  })
}


const cxYcList = () => {
  post({
    url: 'dwWms/dwRubberInStock/getPage',
    data: {
      page: fySelet2.page,
      size: fySelet2.size,
      companyId: pageData.a,
      warehouseId: pageData.b,
      orderNo: pageData.g,
    }
  }).then((res: any) => {
    gridOption.value.setRowData(res.data.data)
    tableDataList.value = res.data.data
    fySelet2.total = res.data.total
  })
}

const cgRoutList: any = ref([])

const redersOut = () => {
  if (tabsKeys.value == 2) {
    if (gridOption2.value.getSelectedRows().length == 0) {
      Message.error('请选择采购单')
      return
    }
    for (let i = 0; i < gridOption2.value.getSelectedRows().length; i++) {
      for (let j = i + 1; j < gridOption2.value.getSelectedRows().length; j++) {
        if (gridOption2.value.getSelectedRows()[i].purchaseOrderNo != gridOption2.value.getSelectedRows()[j].purchaseOrderNo) {
          Message.error('请勾选相同采购单入库')
          return
        }
      }
    }
    cgData.value = JSON.parse(JSON.stringify(gridOption2.value.getSelectedRows()))
    cgData.value.forEach((e: any) => {
      e['totalNum'] = e['notInStockNum']
    })

    post({
      url: 'dwWms/warehouse/getWarehouseByPara',
      data: {
        firmId: gridOption2.value.getSelectedRows()[0].companyId,
        warehouseTypeName: '胶管仓'
      }
    }).then((res: any) => {
      if (res.code == 200) {
        cgRoutList.value = res.data
      }
    })

    cgOut.visible = true
  } else if (tabsKeys.value == 3) {
    if (gridOption3.value.getSelectedRows().length == 0) {
      Message.error('请选择调拨单')
      return
    }
    for (let i = 0; i < gridOption3.value.getSelectedRows().length; i++) {
      for (let j = i + 1; j < gridOption3.value.getSelectedRows().length; j++) {
        if (gridOption3.value.getSelectedRows()[i].orderNo != gridOption3.value.getSelectedRows()[j].orderNo) {
          Message.error('请勾选相同调拨单入库')
          return
        }
      }
    }
    cgData2.value = JSON.parse(JSON.stringify(gridOption3.value.getSelectedRows()))
    cgOut.title = '调拨单入库'
    cgOut.visible = true
  }
}

const cgOut = reactive({
  visible: false,
  title: '采购单入库'
})

const cgHandleOk = async () => {
  if (tabsKeys.value == 2) {
    for (let i = 0; i < cgData.value.length; i++) {
      if (cgData.value[i].warehouseName == '' || cgData.value[i].warehouseName == undefined || cgData.value[i].warehouseName == null) {
        Message.error('请选择入库仓库')
        return false
      }
      // if (cgData.value[i].grade == '' || cgData.value[i].grade == undefined || cgData.value[i].grade == null) {
      //     Message.error('请选择批次')
      //     return false
      // }
    }
    cgData.value.forEach((res: any) => {
      res['infoType'] = 1
      res['inStockType'] = '采购入库'
      res['warehouseTypeName'] = '胶管仓'
    })
    const {code, message} = await post({
      url: 'dwWms/dwRubberInStock/addStock',
      data: cgData.value
    })
    if (code == 200) {
      cxYcList()
      cxCgsList()
      warehouseNameAanId.value = ''
      Message.success('成功')
      return true
    }
    Message.error(message)
    return false
  } else if (tabsKeys.value == 3) {
    for (let i = 0; i < cgData2.value.length; i++) {
      if (cgData2.value[i].grade == '' || cgData2.value[i].grade == undefined || cgData2.value[i].grade == null) {
        Message.error('请选择批次')
        return false
      }
    }
    cgData2.value.forEach((res: any) => {
      res['infoType'] = 2
      res['inStockType'] = '调拨入库'
      res['warehouseTypeName'] = '五金仓'
      delete res.firmId
      delete res.firm
      delete res.id
    })
    const {code, message} = await post({
      url: 'dwWms/dwRubberInStock/addStock',
      data: cgData2.value
    })

    if (code == 200) {
      cxYcList()
      cxDbsList()
      Message.success('成功')
      return true
    }

    Message.error(message)
    return false
  }
}

const cgColumns: any = [
  {
    dataIndex: 'purchaseOrderNo',
    key: 'purchaseOrderNo',
    title: '采购单号',
    width: 150,
  },
  {
    dataIndex: 'supplierName',
    key: 'supplierName',
    title: '供应商',
    width: 150,
  },
  {
    dataIndex: 'buyer',
    key: 'buyer',
    title: '采购员',
    width: 150,
  },
  {
    dataIndex: 'clientName',
    key: 'clientName',
    title: '客户名称',
    width: 150,
  },
  {
    dataIndex: 'materialName',
    key: 'materialName',
    title: '物料名称',
    width: 150,
  },
  {
    dataIndex: 'materialCode',
    key: 'materialCode',
    title: '物料编号',
    width: 150,
  },
  {
    dataIndex: 'specification',
    key: 'specification',
    title: '规格',
    width: 150,
  },
  {
    dataIndex: 'unit',
    key: 'unit',
    title: '单位',
    width: 150,
  },
  {
    dataIndex: 'notInStockNum',
    key: 'notInStockNum',
    title: '未入库数量',
    width: 150,
  },
  {
    dataIndex: 'price',
    key: 'price',
    title: '单价',
    width: 150,
  },
  {
    dataIndex: 'noTaxMoney',
    key: 'noTaxMoney',
    title: '价格',
    width: 150,
  },
  // {
  //     dataIndex: 'grade',
  //     key: 'grade',
  //     slotName: 'grade',
  //     title: '批次',
  //     fixed: 'right',
  //     width: 150,
  // },
  {
    dataIndex: 'inStockNum',
    key: 'inStockNum',
    title: '已入库数量 ',
    fixed: 'right',
    width: 150,
  },
  {
    dataIndex: 'totalNum',
    key: 'totalNum',
    title: '采购入库数量',
    fixed: 'right',
    slotName: 'totalNum',
    width: 150,
  },
  {
    dataIndex: 'warehouseName',
    key: 'warehouseName',
    title: '入库仓库',
    fixed: 'right',
    slotName: 'warehouseName',
    width: 150,
  },
  {
    dataIndex: 'location',
    key: 'location',
    title: '储位',
    fixed: 'right',
    slotName: 'location',
    width: 150,
  }
]

const cgColumns2: any = [
  {
    dataIndex: 'orderNo',
    key: 'orderNo',
    title: '调拨单号',
    width: 150,
  },
  {
    dataIndex: 'outStockType',
    key: 'outStockType',
    title: '出库类型',
    width: 150,
  },
  {
    dataIndex: 'companyName',
    key: 'companyName',
    title: '发货公司',
    width: 150,
  },
  {
    dataIndex: 'warehouseTypeName',
    key: 'warehouseTypeName',
    title: '仓库类型',
    width: 150,
  },
  {
    dataIndex: 'warehouseName',
    key: 'warehouseName',
    title: '仓库名称',
    width: 150,
  },
  {
    dataIndex: 'inWarehouseTypeName',
    key: 'inWarehouseTypeName',
    title: '入库仓库类型',
    width: 150,
  },
  {
    dataIndex: 'inCompanyName',
    key: 'inCompanyName',
    title: '入库公司',
    width: 150,
  },
  {
    dataIndex: 'inWarehouseName',
    key: 'inWarehouseName',
    title: '入库仓库名称',
    width: 150,
  },
  {
    dataIndex: 'majorCategory',
    key: 'majorCategory',
    title: '物料大类 ',
    width: 150,
  },
  {
    dataIndex: 'subCategory',
    key: 'subCategory',
    title: '物料小类',
    width: 150,
  },
  {
    dataIndex: 'materialCode',
    key: 'materialCode',
    title: '物料编号',
    width: 150,
  },
  {
    dataIndex: 'materialName',
    key: 'materialName',
    title: '物料名称',
    width: 150,
  },
  {
    dataIndex: 'specification',
    key: 'specification',
    title: '规格',
    width: 150,
  },
  {
    dataIndex: 'totalNum',
    key: 'totalNum',
    title: '数量',
    width: 150,
  },
  {
    dataIndex: 'unit',
    key: 'unit',
    title: '单位',
    width: 150,
  },
  {
    dataIndex: 'grade',
    key: 'grade',
    slotName: 'grade',
    title: '批次',
    fixed: 'right',
    width: 150,
  },
  {
    dataIndex: 'updateTime',
    key: 'updateTime',
    title: '发货时间',
    width: 150,
  }
]

// const warehouseChange = ($event: any, record: any) => {
//     if ($event != '' || $event != undefined) {
//         record['warehouseId'] = Number($event.split('-')[0])
//         record['warehouseName'] = $event.split('-')[1]
//         return
//     }
// }
const warehouseNameAanId: any = ref()
const warehouseChange = () => {
  cgData.value.forEach((res: any) => {
    res['warehouseId'] = Number(warehouseNameAanId.value.split('-')[0])
    res['warehouseName'] = warehouseNameAanId.value.split('-')[1]
  })
}

const cadelvs = () => {
  warehouseNameAanId.value = ''
  cgData.value = []
  cgOut.visible = false
}

const delSles = () => {
  Modal.confirm({
    title: '系统提示',
    content: '确认删除选中的数据?',
    onOk: () => {
      post({
        url: 'dwWms/dwRubberInStock/delete',
        data: gridOption.value.getSelectedRows().map((res: any) => res.id)
      }).then((res: any) => {
        if (res.code == 200) {
          Message.success('删除成功')
          cxYcList()
        } else (
            Message.error(res.message)
        )
      })
    },
  })
}

const audits = () => {
  Modal.confirm({
    title: '系统提示',
    content: '确认删除选中的数据?',
    onOk: () => {
      post({
        url: 'dwWms/dwRubberInStock/audit',
        data: {
          infoState: 2,
          infos: gridOption.value.getSelectedRows().map((res: any) => {
            return {id: res.id}
          })
        }
      }).then((res: any) => {
        if (res.code == 200) {
          Message.success('成功')
          cxYcList()
        } else (
            Message.error(res.message)
        )
      })
    },
  })
}


const cgData: any = ref([])
const cgData2: any = ref([])

const gradrList: any = ref([])

const gradeChange = () => {
  post({
    url: 'dict/dictTypeDetail/getListByMap',
    data: {
      codeType: 26,
      detailName: ''
    }
  }).then(({data, code}: any) => {
    if (code === 200) {
      gradrList.value = data;
    }
  })
}
const configCascader = ref<{}>({
  corporateWidth: '200px', //公司宽度
  sectorWidth: '180px', //部门宽度
  corporateRquired: true, //公司是否必填
  sectorRquired: false, //部门是否必填
  size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
  corporateName: '选择公司', //公司label
  sectorName: '选择部门', //部门label
  cascaderShow: 'sector', //配置部门不显示
})
const changeCascader = (data: any) => {
  const {corporateId, sectorId, sectorLabel, corporateLabel} = data
  pageData.c = corporateId
}
const configCascader2 = ref<{}>({
  corporateWidth: '200px', //公司宽度
  sectorWidth: '180px', //部门宽度
  corporateRquired: false, //公司是否必填
  sectorRquired: false, //部门是否必填
  size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
  corporateName: '选择公司', //公司label
  sectorName: '选择部门', //部门label
  cascaderShow: 'sector', //配置部门不显示
})
const whService = new WHService()
const fhWhList: any = whService.whList
const changeCascader2 = (data: any) => {
  const {corporateId, sectorId, sectorLabel, corporateLabel} = data
  pageData.b = ""
  pageData.a = corporateId
  whService.getWarhouseListByFirmId(corporateId, '胶管仓')
}

const rejecteds = () => {
  Modal.confirm({
    title: '系统提示',
    content: '确认驳回选中的数据?',
    onOk: () => {
      post({
        url: 'dwWms/dwRubberOutStock/audit',
        data: {
          infoState: 1,
          infos: gridOption3.value.getSelectedRows()
        }
      }).then((res: any) => {
        if (res.code == 200) {
          Message.success('成功')
          cxDbsList()
        } else (
            Message.error(res.message)
        )
      })
    },
  })
}

const completes = () => {
  let isEvent = gridOption2.value.getSelectedRows().every(v => v.purchaseOrderNo == gridOption2.value.getSelectedRows()[0].purchaseOrderNo);
  if (!isEvent) Message.info('请选择相同采购单');
  if (!isEvent) return;
  Modal.confirm({
    title: '系统提示',
    content: '确认完成选中的数据?',
    onOk: () => {
      post({
        url: 'dwPurchase/PurchaseOrderDetail/updateByIdsInStock',
        data: gridOption2.value.getSelectedRows().map((res: any) => {
          return res.tempId
        })
      }).then((res: any) => {
        if (res.code == 200) {
          Message.success('成功')
          cxCgsList()
        } else (
            Message.error(res.message)
        )
      })
    },
  })
}
const visibleYl2 = ref(false)


const handleOks2 = async () => {
  await printJS({
    printable: 'wjDyings4',
    type: 'html',
    font_size: '',
    targetStyles: ['*'],
  })
  return true
}

const handleCancels2 = () => {
  visibleYl2.value = false
}

//下拉框得到焦点
const focusSel = () => {
  if (warehouseNameAanId.value == "" || warehouseNameAanId.value == undefined || warehouseNameAanId.value == null) {
    Message.warning({
      content: '请先选入库仓库！',
      duration: 5000,
    })
    return
  }
  selCxAll({storageName: '', warehouseId: Number(warehouseNameAanId.value.split('-')[0])})
}
//下拉数据
const options = ref<any>(pageData.locationList)
const loading = ref(false)
const handleSearch = (value: any) => {
  if (value) {
    const ob = {storageName: value, warehouseId: Number(warehouseNameAanId.value.split('-')[0])}
    loading.value = true
    selCxAll(ob)
    options.value = pageData.locationList
    loading.value = false
  } else {
    options.value = []
  }
}

//下拉框查询
function selCxAll(val: any) {
  post({
    url: 'dwWms/Storage/getFieldValue',
    data: val,
  }).then(({data, code}: any) => {
    if (code === 200) {
      pageData.locationList = data
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}

function printRef() {
  if (gridOption3.value.getSelectedRows().length == 0) {
    Message.error('请勾选数据!')
    return
  }
  let orderNoList = gridOption3.value.getSelectedRows().map((o: any) => {
    return {
      orderNo: o.orderNo
    }
  })
  post({
    url: 'dwWms/dwRubberInStock/getList',
    data: orderNoList,
    responseType: 'blob'
  }).then((res) => {
    let reader = new FileReader();
    reader.readAsDataURL(res);
    reader.onload = function () {
      let pdfBase64 = reader.result.replace('data:application/pdf;base64,', '');
      printJS({printable: pdfBase64, type: 'pdf', base64: true})
    };
  });
}
</script>
<script lang="ts">
export default {
  name: "ReceiptList4",
}
</script>
<style lang="less" scoped>
:deep(.arco-table-td-content) {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>